package cn.szzsi.business.validator;

import cn.szzsi.common.util.CommonUtil;
import cn.szzsi.model.Resource;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * Created by haotian on 2016/9/26.
 */
public class BusinessResourceValidator extends Validator {

    @Override
    protected void validate(Controller c) {
        validateRequiredString("businessResource.name", "nameMessages", "分类名称不允许为空!");
        validateRequiredString("businessResource.orderList", "orderListMessages", "排序不允许为空!");

        validateInteger("businessResource.orderList", 0, 1000, "orderListMessages", "排序必须为零或正整数!");
    }

    @Override
    protected void handleError(Controller c) {

        c.setAttr("businessResourceTreeList", Resource.dao.getByUid(c.getPara("uid")));
        c.render(CommonUtil.TEMPLATE_PATH+"/business/business_resource_input.html");
    }
}
